
******************************
*** Mortality by age group ***
******************************

log using "$plots/Event_study_log.smcl", replace
display "`c(current_time)' `c(current_date)'"


local window_begin = 15
local window_end = 43

foreach a of numlist 1 2 3 4{
use "$altered_data/event_study_vaccination.dta", clear
keep if date >= td(12jul2021) & date <= td(04oct2021)
gen vac_rate_lag14 = cum_cases_14_lag / pop_total

keep if age == `a'


	if `a' == 1 {
		local header "Age: 5 - 14"
	}
	if `a' == 2 {
		local header "Age: 15 - 34"
	} 
	if `a' == 3 {
		local header "Age: 35 - 59"
	} 
	if `a' == 4 {
		local header "Age: 60+"
	}

	
did_multiplegt deaths_by_age RS date treated, robust_dynamic controls(cases_cum14 vac_rate_lag14 mob*)  placebo(`window_begin') dynamic(`window_end') breps(100) cluster(idbundesland) weight(pop_total) save_results("$altered_data/did_multiplegt_main_`a'_mort.dta")

use "$altered_data/did_multiplegt_main_`a'_mort.dta", clear
scatter treatment_effect treatment_effect_lower_95CI treatment_effect_upper_95CI time_to_treatment, ///
c(l l l) cmissing(n n n) msym(i i i) lcolor(gs4 gs10 gs10) lpattern(solid solid solid) lwidth(thick medthick medthick) ///
yline(0, lcolor(black)) xline(0, lcolor(black)) ///
legend(order(1  2) label(1 "Point estimates") label(2 "95% CI") cols(2)) ///
subtitle("", size(vsmall) j(left) pos(11)) ///
ylabel(-0.5(0.5)0.5,nogrid angle(horizontal) labsize(small)) graphregion(color(white)) ///
xtitle("Days relative to end of summer break") xlab(-`window_begin'(5)`window_end')  name("did_gt_`a'", replace)  title("`header'", color(black))  
}

grc1leg did_gt_1 did_gt_2 did_gt_3 did_gt_4, graphregion(color(white)) ycommon
graph export "${plots}chaise_main_mort_age.png", replace width(3000)




